package my.headfirstjava.observer.v3;

import java.util.Observable;
import java.util.Observer;

/**
 * author: xl
 * time: 2018/8/23 9:43
 * description:
 **/
public class ForecastWeather implements Observer,Display {


    private Observable observable= null;


    public  ForecastWeather(Observable observable){
        this.observable = observable;
        observable.addObserver(this);
    }


    @Override
    public void display(WeatherData msg) {
        System.out.println("预计三天天气，温度:"+msg.getWendu());
        System.out.println("预计三天天气，湿度:"+msg.getShidu());
        System.out.println("预计三天天气，气压:"+msg.getQiya());
    }

    @Override
    public void update(Observable observable, Object arg) {
         if(observable instanceof Subject){
             WeatherData msg=((Subject) observable).getWeatherData();
             display(msg);
         }
    }
}
